<?php

//Tao Lop DOI_TUONG
class Bep {

    private $_BEP_ID;
    private $_BEP_TEN_BEP;
    private $_BEP_IS_THUE;
    private $_IS_ACTIVE;

   
    public function getBEP_ID() {
        return $this->_BEP_ID;
    }

    public function getBEP_TEN_BEP() {
        return $this->_BEP_TEN_BEP;
    }

    public function getBEP_IS_THUE() {
        return $this->_BEP_IS_THUE;
    }

    public function setBEP_ID($BEP_ID) {
        $this->_BEP_ID = $BEP_ID;
    }

    public function setBEP_TEN_BEP($BEP_TEN_BEP) {
        $this->_BEP_TEN_BEP = $BEP_TEN_BEP;
    }

    public function setBEP_IS_THUE($BEP_IS_THUE) {
        $this->_BEP_IS_THUE = $BEP_IS_THUE;
    }

        public function getIS_ACTIVE() {
        return $this->_IS_ACTIVE;
    }

    public function setIS_ACTIVE($IS_ACTIVE) {
        $this->_IS_ACTIVE = $IS_ACTIVE;
    }

        public function SetBep($row) {
        $this->setBEP_ID($row->BEP_ID);
        $this->setBEP_TEN_BEP($row->BEP_TEN_BEP);
         $this->setBEP_IS_THUE($row->BEP_IS_THUE);
        $this->setIS_ACTIVE($row->IS_ACTIVE);
    }

    public function insert($db = null) {
        if ($db != null) {
            $sql = "INSERT INTO `bep`
                                (
                                 
                                 `BEP_ID`,
                                 `BEP_TEN_BEP`,
                                 `BEP_IS_THUE`,
                                 `IS_ACTIVE`
)
                    VALUES (
                                 :BEP_ID,
                                 :BEP_TEN_BEP,
                                 :BEP_IS_THUE,
                                 :IS_ACTIVE);";
            $parameters = array(
                ":BEP_ID",
                ":BEP_TEN_BEP",
                ":BEP_IS_THUE",
                ":IS_ACTIVE"
            );
            $values = array(
                
                $this->getBEP_ID(),
                $this->getBEP_TEN_BEP(),
                $this->getBEP_IS_THUE(),
                1);
            $types = array(
                PDO::PARAM_INT,
                PDO::PARAM_STR,
                PDO::PARAM_INT,
                PDO::PARAM_INT
            );
            $lastInsertID = $db->executeNonQuery($sql, $parameters, $values, $types, true);
            $this->setBEP_ID($lastInsertID);
        }
    }

    public function delete($db = null) {
        if ($db != null) {
            $sql = "delete
                    from `bep`
                    where `BEP_ID` = :BEP_ID;";
            $parameters = array(":BEP_ID");
            $values = array($this->getBEP_ID());
            $types = array(PDO::PARAM_INT);
            $result = $db->executeNonQuery($sql, $parameters, $values, $types);
            return $result;
        }
    }

    public function update($db = null) {
        if ($db != null) {
            $sql = "UPDATE `bep`
                    SET `BEP_ID` = :BEP_ID,
                      `BEP_TEN_BEP` = :BEP_TEN_BEP,
                      `BEP_IS_THUE` = :BEP_IS_THUE
                    WHERE `BEP_ID` = :BEP_ID;";
            $parameters = array(
                ":BEP_ID", ":BEP_TEN_BEP",
                ":BEP_IS_THUE");
            $values = array(
                $this->getBEP_ID(),
                $this->getBEP_TEN_BEP(),
                $this->getBEP_IS_THUE());
            $types = array(
                PDO::PARAM_INT,
                PDO::PARAM_STR, PDO::PARAM_INT
            );
            $result = $db->executeNonQuery($sql, $parameters, $values, $types);
            return $result;
        }
    }

    public function getByID($db = null) {
        if ($db != null) {
            $sql = "SELECT
                        `BEP_ID`,
                         `BEP_TEN_BEP`,
                                 `BEP_IS_THUE`,
                                 `IS_ACTIVE`
                      FROM `bep`
                      WHERE BEP_ID = :BEP_ID";
            $parameters = array(":BEP_ID");
            $values = array($this->getBEP_ID());
            $types = array(PDO::PARAM_INT);
            $rows = $db->executeQuery($sql, $parameters, $values, $types);
            if ($rows != null) {
                $row = $rows->fetch();
                $this->setBEP_ID($row->BEP_ID);
                 $this->setBEP_TEN_BEP($row->BEP_TEN_BEP);
                 $this->setBEP_IS_THUE($row->BEP_IS_THUE);
                $this->setIS_ACTIVE($row->IS_ACTIVE);
                
            }
            return $this;
        }
    }

    public function getList($db = null) {
        if ($db != null) {
            $sql = "SELECT
                        `BEP_ID`,
                         `BEP_TEN_BEP`,
                                 `BEP_IS_THUE`,
                                 `IS_ACTIVE`
                  FROM `bep`";
            $rows = $db->executeQuery($sql);
            $objects = array();
            if ($rows != null) {
                while ($row = $rows->fetch()) {
                    $bep = new Bep();
                    $bep->setBEP_ID($row->BEP_ID);
                    $bep->setBEP_TEN_BEP($row->BEP_TEN_BEP);
                    $bep->setBEP_IS_THUE($row->BEP_IS_THUE);
                    $bep->setIS_ACTIVE($row->IS_ACTIVE);

                    $objects[] = $bep;
                }
                return $objects;
            }
        }
    }

}
